package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiParam(value = "查询所有护理计划")
    public ResponseResult<NursingPlanVo> selectAll() {
        return ResponseResult.success(nursingPlanService.selectAll());
    }

    @PostMapping
    @ApiParam(value = "新增护理计划")
    public ResponseResult addPlan(
            @ApiParam(value = "护理计划信息", required = true)
            @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/search")
    @ApiOperation("根据名称和状态分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> pageSearch(
            @ApiParam(value = "护理计划名称")
            @RequestParam(required = false) String name,
            @ApiParam(value = "护理计划状态")
            @RequestParam(required = false) Integer status,
            @ApiParam(value = "页码（默认为1）")
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页大小（默认为10）")
            @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return ResponseResult.success(nursingPlanService.pageSearch(name, status, pageNum, pageSize));
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理计划")
    public ResponseResult<NursingPlanVo> getPlanById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id){
        return ResponseResult.success(nursingPlanService.getPlanById(id));
    }

    @PutMapping("/{id}")
    @ApiOperation("更新护理计划")
    public ResponseResult updatePlan(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id,
            @ApiParam(value = "护理计划信息", required = true)
            @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updatePlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deletePlan(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id){
        nursingPlanService.deletePlan(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用")
    public ResponseResult ture_false(
            @ApiParam(value = "护理计划ID", required = true)
            Long id,
            @ApiParam(value = "状态", required = true)
            Integer status){
        nursingPlanService.ture_false(id, status);
        return ResponseResult.success();
    }
}
